package com.mystyle.le.weekproject.asynctaks;

import android.content.Context;
import android.os.AsyncTask;

import com.mystyle.le.weekproject.beans.Boutiques;
import com.mystyle.le.weekproject.beans.Manchester;
import com.mystyle.le.weekproject.intentfactbackcall.MyCallBack;
import com.mystyle.le.weekproject.utils.DownData;
import com.mystyle.le.weekproject.utils.ParseJson;

import java.util.List;

/**
 *下载精品页面的今日推荐任务
 * Created by le on 2016/10/10.
 */
public class BoutiqueAsyncTaks extends AsyncTask<String,Void,List<Boutiques>> {
    private MyCallBack.BoutiqueBack1 boutiqueBack;
    private Context context;

    public BoutiqueAsyncTaks(MyCallBack.BoutiqueBack1 boutiqueBack, Context context) {
        this.boutiqueBack = boutiqueBack;
        this.context = context;
    }

    @Override
    protected List<Boutiques> doInBackground(String... params) {
        boolean netWorkConn = DownData.isNetWorkConn(context);
        if (netWorkConn){
            String param = params[0];
            byte[] bytes = DownData.downData(param);
            if (bytes!=null&&bytes.length>0){
                String pathJson = new String(bytes,0,bytes.length);
                return ParseJson.parseBoutiquesJson(pathJson,1);
            }
         }
       return null;
    }

    @Override
    protected void onPostExecute(List<Boutiques> manchesters) {
        super.onPostExecute(manchesters);
        if (manchesters!=null&&manchesters.size()>0){
            boutiqueBack.sendData(manchesters);
        }
    }
}
